import 'package:flutter/material.dart';
import 'package:flutter_dva/flutter_dva.dart';
import 'package:example/src/models/home.dart';
import '../models/mapper.dart';

class MyHomePage extends StatefulWidget {
  final String? title;
  const MyHomePage({this.title, Key? key}) : super(key: key);
  @override
  State<StatefulWidget> createState() => MyHomePageState();
}

class MyHomePageState extends Connect<MyHomePage> {

  void incrementCounter() {
    props?.dispatch(HomeModel.incrementCounter, namespace: 'home');
  }

  @override
  Widget build(BuildContext context) {
    num? count = state.home?.count;
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title ?? "")
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('You have pushed the button this many times:',),
            Text(
              '$count',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}